// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import VueResource from 'vue-resource'

/**
 * 引入echart模块
 * 1.cnpm install echarts --save
 * 2、然后在main.js中添加如下内容：
 * import echarts from 'echarts'
 * Vue.prototype.$echarts=echarts;
 * @type {boolean}
 */

import echarts from 'echarts'


Vue.prototype.$echarts = echarts;

Vue.config.productionTip = false

// 使用官方插件
Vue.use(ElementUI);
Vue.use(VueResource);

//获取cookie、
function getCookie(name) {
  var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  if (arr = document.cookie.match(reg))
    return (arr[2]);
  else
    return null;
}
Vue.prototype.getCookie = getCookie;


new Vue({
  router: router,
  el: '#app',
  render: h => h(App),
  components: {App},
  template: '<App/>',
  //监听路由检查登录
  watch:{
    "$route" : 'checkLogin'
  },
  //进入页面时前端检查是否已经登录
  created() {
    // this.checkLogin();
  },
  methods: {
    checkLogin() {
      // if (this.getCookie('seesion')) {
      //   //如果没有登录状态则跳转到登录页
      //   this.$router.push('/login');
      // } else {
      //   //否则跳转到登录后的页面
      //   this.$router.push('/main');
      // }
    }
  }
})
